package com.ruoyi.web.controller.workJob;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.worker.domain.Company;
import com.ruoyi.worker.domain.CompanyDto;
import com.ruoyi.worker.domain.WorkerInfos;
import com.ruoyi.worker.service.CompanyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
import java.util.Map;

/**
 * @ClassName CompanyApi
 * @Description 渠道api
 * @Author zhangxx
 * @Date 2021/8/28 23:59
 * @Version 1.0
 */
@RestController
@RequestMapping("/companyApi")
public class CompanyApi extends BaseController {
    @Autowired
    private CompanyService companyService;

    @GetMapping("/list")
    public TableDataInfo getCompanyListInfo(Company company) {
        startPage();
        List<Company> companyList = companyService.getCompanyList(company);
        return getDataTable(companyList);
    }

    @GetMapping("/export")
    public AjaxResult export(Company company) {
        List<Company> workerInfos = companyService.getCompanyList(company);
        ExcelUtil<Company> util = new ExcelUtil<Company>(Company.class);
        return util.exportExcel(workerInfos, "渠道信息");
    }

    //  @PreAuthorize("@ss.hasPermi('system:role:edit')")
    @Log(title = "渠道管理", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public AjaxResult changeStatus(@RequestBody Map<String, Object> requestParam) {
        return toAjax(companyService.updateStatus(requestParam));
    }

    @Log(title = "渠道管理", businessType = BusinessType.UPDATE)
    @PostMapping("/insert")
    public AjaxResult insert(@RequestBody Company company) {
        return toAjax(companyService.insertCompany(company));
    }

    @Log(title = "渠道管理", businessType = BusinessType.UPDATE)
    @GetMapping("/getCompany/{id}")
    public AjaxResult getCompany(@PathVariable int id) {
        return AjaxResult.success(companyService.getCompany(id));
    }

    @GetMapping("/getCompany/")
    public AjaxResult getCompanyList(Company company) {
        return AjaxResult.success(companyService.getCompanyList(company));
    }


    @PreAuthorize("@ss.hasPermi('setting:company:delete')")
    @Log(title = "渠道管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    public AjaxResult delCompany(@PathVariable int id) {
        return toAjax(companyService.deleteCompany(id));
    }

    @PreAuthorize("@ss.hasPermi('setting:company:edit')")
    @Log(title = "渠道管理", businessType = BusinessType.UPDATE)
    @PutMapping("/update")
    public AjaxResult update(@RequestBody Company company) {
        return toAjax(companyService.updateCompany(company));
    }

    @PreAuthorize("@ss.hasPermi('setting:company:percent')")
    @Log(title = "渠道管理", businessType = BusinessType.UPDATE)
    @PutMapping("/updateRecruitPercent")
    public AjaxResult updateRecruitPercent(@RequestBody List<Company> companyList) {
        return toAjax(companyService.updateCompanyBatch(companyList));
    }
}
